<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Customizing Zend_Queue - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.queue.custom.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.queue.custom.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.queue.adapters.html">Adapters</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.queue.html">Zend_Queue</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.queue.stomp.html">Stomp</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.queue.custom" class="section"><div class="info"><h1 class="title">Customizing Zend_Queue</h1></div>
    

    <div class="section" id="zend.queue.custom.adapter"><div class="info"><h1 class="title">Creating your own adapter</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Queue</span> will accept any adapter that
            implements
            <span class="classname">Zend_Queue_Adapter_AdapterAbstract</span>. You can
            create your own adapter by extending one of the existing adapters,
            or the abstract class
            <span class="classname">Zend_Queue_Adapter_AdapterAbstract</span>. I
            suggest reviewing <span class="classname">Zend_Queue_Adapter_Array</span> as
            this adapter is the easiest to conceptualize.
        </p>

        <pre class="programlisting brush: php">
class Custom_DbForUpdate extends Zend_Queue_Adapter_Db
{
    /**
     * @see code in tests/Zend/Queue/Custom/DbForUpdate.php
     *
     * Custom_DbForUpdate uses the SELECT ... FOR UPDATE to find it&#039;s rows.
     * this is more likely to produce the wanted rows than the existing code.
     *
     * However, not all databases have SELECT ... FOR UPDATE as a feature.
     *
     * Note: this was later converted to be an option for Zend_Queue_Adapter_Db
     *
     * This code still serves as a good example.
     */
}

$options = array(
    &#039;name&#039;          =&gt; &#039;queue1&#039;,
    &#039;driverOptions&#039; =&gt; array(
        &#039;host&#039;      =&gt; &#039;127.0.0.1&#039;,
        &#039;port&#039;      =&gt; &#039;3306&#039;,
        &#039;username&#039;  =&gt; &#039;queue&#039;,
        &#039;password&#039;  =&gt; &#039;queue&#039;,
        &#039;dbname&#039;    =&gt; &#039;queue&#039;,
        &#039;type&#039;      =&gt; &#039;pdo_mysql&#039;
    )
);

$adapter = new Custom_DbForUpdate($options);
$queue = new Zend_Queue($adapter, $options);
</pre>


        <p class="para">
            You can also change the adapter on the fly as well.
        </p>

        <pre class="programlisting brush: php">
$adapter = new MyCustom_Adapter($options);
$queue   = new Zend_Queue($options);
$queue-&gt;setAdapter($adapter);
echo &quot;Adapter: &quot;, get_class($queue-&gt;getAdapter()), &quot;\n&quot;;
</pre>


        <p class="para">or</p>

        <pre class="programlisting brush: php">
$options = array(
    &#039;name&#039;           =&gt; &#039;queue1&#039;,
    &#039;namespace&#039;      =&gt; &#039;Custom&#039;,
    &#039;driverOptions&#039;  =&gt; array(
        &#039;host&#039;       =&gt; &#039;127.0.0.1&#039;,
        &#039;port&#039;       =&gt; &#039;3306&#039;,
        &#039;username&#039;   =&gt; &#039;queue&#039;,
        &#039;password&#039;   =&gt; &#039;queue&#039;,
        &#039;dbname&#039;     =&gt; &#039;queue&#039;,
        &#039;type&#039;       =&gt; &#039;pdo_mysql&#039;
    )
);
$queue = new Zend_Queue(&#039;DbForUpdate&#039;, $config); // loads Custom_DbForUpdate
</pre>

    </div>

    <div class="section" id="zend.queue.custom.message"><div class="info"><h1 class="title">Creating your own message class</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Queue</span> will also accept your own message class.
            Our variables start with an underscore. For example:
        </p>

        <pre class="programlisting brush: php">
class Zend_Queue_Message
{
    protected $_data = array();
}
</pre>


        <p class="para">
            You can extend the existing messaging class. See the example code in
            <var class="filename">tests/Zend/Queue/Custom/Message.php</var>.
        </p>
    </div>

    <div class="section" id="zend.queue.custom-iterator"><div class="info"><h1 class="title">Creating your own message iterator class</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Queue</span> will also accept your own message
            iterator class. The message iterator class is used to return
            messages from
             <span class="methodname">Zend_Queue_Adapter_Abstract::recieve()</span>.
             <span class="methodname">Zend_Queue_Abstract::receive()</span> should always
            return a container class like
            <span class="classname">Zend_Queue_Message_Iterator</span>, even if there is
            only one message.
        </p>

        <p class="para">
            See the example filename in
            <var class="filename">tests/Zend/Queue/Custom/Messages.php</var>.
        </p>
    </div>

    <div class="section" id="zend.queue.custom.queue"><div class="info"><h1 class="title">Creating your own queue class </h1></div>
        

        <p class="para">
            <span class="classname">Zend_Queue</span> can also be overloaded easily.
        </p>

        <p class="para">
            See the example filename in <var class="filename">tests/Zend/Queue/Custom/Queue.php</var>.
        </p>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.queue.adapters.html">Adapters</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.queue.html">Zend_Queue</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.queue.stomp.html">Stomp</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.queue.html">Zend_Queue</a></li>
  <li><a href="zend.queue.introduction.html">Introduction</a></li>
  <li><a href="zend.queue.example.html">Example usage</a></li>
  <li><a href="zend.queue.framework.html">Framework</a></li>
  <li><a href="zend.queue.adapters.html">Adapters</a></li>
  <li class="active"><a href="zend.queue.custom.html">Customizing Zend_Queue</a></li>
  <li><a href="zend.queue.stomp.html">Stomp</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>